package com.nsu.evaluation.service.impl;

import com.nsu.evaluation.common.ServerResponse;
import com.nsu.evaluation.dao.FeedbackReplyMapper;
import com.nsu.evaluation.dao.StudentEvaluationsMapper;
import com.nsu.evaluation.pojo.FeedbackReply;
import com.nsu.evaluation.pojo.StudentEvaluations;
import com.nsu.evaluation.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;

public class ScheduleServiceImpl implements ScheduleService {

    @Autowired
    private StudentEvaluationsMapper studentEvaluationsMapper;

    @Autowired
    private FeedbackReplyMapper feedbackReplyMapper;

    /**
     * 新增学生评价
     * @param studentEvaluations
     * @return
     */
    @Override
    public ServerResponse<StudentEvaluations> addStudentEvaluation(StudentEvaluations studentEvaluations){
        int rowCount = studentEvaluationsMapper.insert(studentEvaluations);
        if(rowCount > 0){
            return ServerResponse.createBySuccess("新增评价成功",studentEvaluations);
        }
        return ServerResponse.createByErrorMessage("新增评价失败");
    }

    /**
     * 修改学生评价
     * @param studentEvaluations
     * @return
     */
    @Override
    public ServerResponse<StudentEvaluations> updateStudentEvaluation(StudentEvaluations studentEvaluations){
        int rowCount = studentEvaluationsMapper.updateByPrimaryKey(studentEvaluations);
        if(rowCount > 0){
            return ServerResponse.createBySuccess("修改评价成功",studentEvaluations);
        }
        return ServerResponse.createByErrorMessage("修改评价失败");
    }

    /**
     * 回复学生申诉
     * @param feedbackReply
     * @return
     */
    @Override
    public ServerResponse<FeedbackReply> replyStudentFeedback(FeedbackReply feedbackReply){
        int rowCount = feedbackReplyMapper.insert(feedbackReply);
        if(rowCount > 0){
            return ServerResponse.createBySuccess("回复学生申诉成功",feedbackReply);
        }
        return ServerResponse.createByErrorMessage("回复学生申诉失败");
    }
}
